/**
 * 会话转接相关API
 */
import request from '@/utils/request';

/**
 * 获取待转接的会话列表
 */
export function getPendingTransfers() {
  return request.get('/api/session-transfer/pending');
}

/**
 * 获取会话转接历史记录
 * @param {Object} params - 查询参数
 */
export function getTransferHistory(params) {
  return request.get('/api/session-transfer/history', { params });
}

/**
 * 获取会话转接历史记录（分页）
 * @param {Object} params - 查询参数
 * @param {number} params.current - 当前页码
 * @param {number} params.size - 每页大小
 * @param {string} [params.startDate] - 开始日期
 * @param {string} [params.endDate] - 结束日期
 * @param {number} [params.serviceId] - 客服ID
 */
export function getTransferHistoryPage(params) {
  return request.get('/api/session-transfer/page', { params });
}

/**
 * 获取转接详情
 * @param {string} transferId - 转接记录ID
 */
export function getTransferDetail(transferId) {
  return request.get(`/api/session-transfer/${transferId}`);
}

/**
 * 发起会话转接
 * @param {Object} data - 转接数据
 * @param {string} data.sessionId - 会话ID
 * @param {number} data.fromServiceId - 转出客服ID
 * @param {number} data.toServiceId - 转入客服ID
 * @param {string} data.reason - 转接原因
 */
export function initiateTransfer(data) {
  return request.post('/api/session-transfer/initiate', data);
}

/**
 * 接受会话转接
 * @param {string} transferId - 转接记录ID
 */
export function acceptTransfer(transferId) {
  return request.post(`/api/session-transfer/${transferId}/accept`, { serviceId: transferId });
}

/**
 * 拒绝会话转接
 * @param {string} transferId - 转接记录ID
 * @param {string} reason - 拒绝原因
 */
export function rejectTransfer(transferId, reason) {
  return request.post(`/api/session-transfer/${transferId}/reject`, { serviceId: transferId, rejectReason: reason });
}

/**
 * 取消会话转接
 * @param {string} transferId - 转接记录ID
 */
export function cancelTransfer(transferId) {
  return request.post(`/api/session-transfer/${transferId}/cancel`, { serviceId: transferId });
}

/**
 * 获取指定会话的转接记录
 * @param {string} sessionId - 会话ID
 */
export function getSessionTransfers(sessionId) {
  return request.get('/api/session-transfer/history', { params: { sessionId } });
}

export default {
  getPendingTransfers,
  getTransferHistory,
  getTransferHistoryPage,
  getTransferDetail,
  initiateTransfer,
  acceptTransfer,
  rejectTransfer,
  cancelTransfer,
  getSessionTransfers
}; 